package com.huawei.M01.iterator.M25;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * 2409. 统计共同度过的日子数
 *
 * @author lizhiwu
 */
public class DaysTogether {
    public int countDaysTogether(String arriveAlice, String leaveAlice, String arriveBob, String leaveBob) {
        int[] monthDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] dayOfMonth = new int[13];
        for (int i = 0; i < 12; i++) {
            dayOfMonth[i + 1] = monthDays[i] + dayOfMonth[i];
        }
        // 将当前时间转换成为天数
        long aArrive = getTime(dayOfMonth, arriveAlice);
        long aLeave = getTime(dayOfMonth, leaveAlice);
        long bArrive = getTime(dayOfMonth, arriveBob);
        long bLeave = getTime(dayOfMonth, leaveBob);
        return (int)Math.max(0, (Math.min(aLeave, bLeave) - Math.max(aArrive, bArrive)) + 1);
    }

    private long getTime(int[] dayOfMonth, String timeStr) {
        int daysOfMonth = dayOfMonth[Integer.parseInt(timeStr.split("-")[0]) - 1];
        return daysOfMonth + Integer.parseInt(timeStr.split("-")[1]);
    }

    public static void main(String[] args) throws ParseException {
        System.out.println(new DaysTogether().countDaysTogether("08-15", "08-18", "08-16", "08-19"));
    }
}
